package com.eims.ball.info.adapter;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.contans.view.FenxiJibenVo;
import com.contans.view.FenxiTeamFutureVo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;
import bls.juejin.cn.R;

public class FanxiJibenMainfutureListAdapter extends BaseAdapter {
	private Context context;
 private FenxiJibenVo jibenVo;
 private ArrayList<FenxiTeamFutureVo> mainFutureVo;



	public FanxiJibenMainfutureListAdapter(Context context,FenxiJibenVo jibenVo) {
		super();
		this.context = context;
		this.jibenVo=jibenVo;
		mainFutureVo=jibenVo.getMainFutureVo();
	}

	@Override
	public int getCount() {
	if (mainFutureVo!=null) {
		return mainFutureVo.size();
	}

		return 0;
	}

	@Override
	public Object getItem(int position) {

		return position;
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		ViewHolder holder;
		// 判断View是否为空
		if (view == null) {
			holder = new ViewHolder();

		
			view = LayoutInflater.from(context).inflate(R.layout.fenxi_jiben_main_future_listview_item, null);
			

			holder.tv_time = (TextView) view.findViewById(R.id.tv_time);
			holder.tv_saishi = (TextView) view.findViewById(R.id.tv_saishi);
			holder.tv_bifen = (TextView) view.findViewById(R.id.tv_bifen);
			holder.tv_main_team = (TextView) view.findViewById(R.id.tv_main_team);

			holder.tv_gues_team = (TextView) view.findViewById(R.id.tv_gues_team);
			holder.tv_saiguo = (TextView) view.findViewById(R.id.tv_saiguo);
			
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		holder.tv_time.setText(mainFutureVo.get(position).getTime());
		holder.tv_saishi.setText(mainFutureVo.get(position).getMatch());
		holder.tv_main_team.setText(mainFutureVo.get(position).getHost());
		holder.tv_gues_team.setText(mainFutureVo.get(position).getGuest());
		holder.tv_saiguo.setText(mainFutureVo.get(position).getLater());
	
		return view;
	}

	public boolean isMobileNO(String mobiles) {
		Pattern p = Pattern.compile("1[0-9]{10}");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}


	static class ViewHolder {
		
		TextView tv_time,tv_saishi,tv_bifen,tv_main_team,tv_gues_team,tv_saiguo;
	}

	

	public String formateRate(String rateStr) {
		if (rateStr.indexOf(".") != -1) {
			
			int num = 0;
			num = rateStr.indexOf(".");

			
			String dianAfter = rateStr.substring(0, num + 1);
			String afterData = rateStr.replace(dianAfter, "");
			if (afterData.length() < 2) {
				afterData = afterData + "0";
			} else {
				afterData = afterData;
			}
			return rateStr.substring(0, num) + "." + afterData.substring(0, 2);
		} else {
			if (rateStr == "1") {
				return "100";
			} else {
				return rateStr;
			}
		}
	}

}
